﻿namespace Lab3_4Tests
open NUnit.Framework
open FsUnit
open Lab3_4
open Helper

[<TestFixture>]
type ``Testing lab 3 4`` ()=
  let lst = [(-1.0,-1.7854);
             (0.0,0.0);
             (1.0, 1.7854);
             (2.0, 3.1071);
             (3.0, 4.249)]

  let lst2 = [(0.0, 1.0);
              (0.1, 1.1052);
              (0.2, 1.2214);
              (0.3, 1.3499);
              (0.4, 1.4918);]

  [<Test>] 
  member t.X ()=
    X (1, 2) |> should equal 1
  [<Test>] 
  member t.Y ()=
    Y (1, 2) |> should equal 2
  [<Test>] 
  member t.``Get right borders`` ()=
    borders lst 1.0 |> should equal ((0.0,0.0), (1.0, 1.7854), (2.0, 3.1071))
    borders lst 1.1 |> should equal ((1.0, 1.7854), (2.0, 3.1071),(3.0, 4.249))
    borders lst 0.5 |> should equal ((0.0,0.0), (1.0, 1.7854), (2.0, 3.1071))
    borders lst -0.5 |> should equal ((-1.0,-1.7854), (0.0,0.0), (1.0, 1.7854))
    <@ borders lst 2.5 @> |>! typeof<System.ArgumentOutOfRangeException>
    <@ borders lst 6.5 @> |>! typeof<System.ArgumentOutOfRangeException>
    <@ borders lst -5.5 @> |>! typeof<System.ArgumentOutOfRangeException>
    borders lst2 0.1 |> should equal ((0.0,1.0), (0.1, 1.1052), (0.2, 1.2214))
    borders lst2 0.3 |> should equal ((0.2, 1.2214), (0.3, 1.3499), (0.4, 1.4918))
  [<Test>]
  member t.``Subtract division`` ()=
    let i,i1,_ = (borders lst 1.0)
    subdiv (i,i1) |> should equal 1.7854
    let i,i1,_ = (borders lst 1.1)
    subdiv (i,i1) |> should equal 1.3216999999999999
    subdiv ((1.5,3.2), (2.0,2.3)) |> should equal -1.8000000000000007

  [<Test>]
  member t.``First derivative`` ()=
    let f' = !lst2
    f' 0.2 |> should equal 1.2235000000000009
  [<Test>]
  member t.``Second derivative`` ()=
    let f'' = !!lst2
    f'' 0.2 |> should equal 1.23
  [<Test>]
  member t.``Lab derivation`` ()=
    let f', f'' = !lst, !!lst
    f' 1.0 |> should equal 1.55355
    f'' 1.0 |> should equal -0.46370000000000022
